package service

import (
	"goconfcenter/dao/mysql"
	"goconfcenter/models"
	"goconfcenter/pkg/snowflake"
	"time"
)

type RoleResourceRelService struct {
}

func RoleResourceRelServiceInstance() *RoleResourceRelService {
	return &RoleResourceRelService{}
}
func (c *RoleResourceRelService) GetListByRoleId(roleId int64) []*models.RoleResourceRel {
	return mysql.RoleResourceRelDaoInstance().GetListByRoleId(roleId)
}
func (c *RoleResourceRelService) SaveRel(roleId int64, resIds []int64, operatorId int64) bool {
	var result bool
	mysql.RoleResourceRelDaoInstance().DeleteAll(roleId)
	roleResourceRelList := make([]*models.RoleResourceRel, 0)
	for _, v := range resIds {
		one := models.RoleResourceRel{}
		one.RoleId = roleId
		one.ResourceId = v
		one.Creator = operatorId
		one.CreateTime = time.Now()
		one.ID = snowflake.GenID()
		roleResourceRelList = append(roleResourceRelList, &one)
	}
	result = mysql.RoleResourceRelDaoInstance().BathInsert(roleResourceRelList)
	return result
}
